package com.huluobo.a2203kotlindouyindemo.home

import androidx.lifecycle.MutableLiveData
import com.huluobo.base.bean.SearchBean
import com.huluobo.base.bean.VideoBeanResult
import com.huluobo.base.viewmodel.BaseViewModel

/**
 *  Created by LC on 2024/7/12.
 */
class HomeViewModel : BaseViewModel<HomeRepo>() {
    val getVideosSuccess = MutableLiveData<VideoBeanResult>()
    val getVideosFailed = MutableLiveData<String>()

    val findVideosSuccess = MutableLiveData<VideoBeanResult>()
    val findVideosFailed = MutableLiveData<String>()

    val querySearchSuccess = MutableLiveData<List<SearchBean>>()
    val querySearchFailed = MutableLiveData<String>()

    fun querySearch() {
        repo.querySearchKeywords(querySearchSuccess, querySearchFailed)
    }

    fun saveSearch(keyword: String) {
        val searchBean = SearchBean(keyword, 0)
        repo.saveSearch(searchBean)
    }

    fun findVideos(keyword: String) {
        repo.findVideos(keyword, findVideosSuccess, findVideosFailed)
    }

    fun getVideos(currentPage: Int, pageSize: Int) {
        repo.getVideoList(currentPage, pageSize, getVideosSuccess, getVideosFailed)
    }

    override fun createRepo(): HomeRepo = HomeRepo()
}